package com.example.tests;

import static org.testng.Assert.assertEquals;

import java.util.Collections;
import java.util.List;

import org.testng.annotations.Test;


public class PersonCreationTests extends TestBase{

  @Test(dataProvider = "randomValidPersonGenerator")
  public void testPersonCreationWithValidData(PersonData person) throws Exception {
    app.getNavigationHelper().openMainPage();
    
    // save old state
    List<PersonData> oldList = app.getPersonHelper().getPersons();
    
    //actions
    app.getPersonHelper().initPersonCreation();
    app.getPersonHelper().fillAddNewPersonPage(person);
    app.getNavigationHelper().submitForm();
    app.getPersonHelper().returnToHomePage();
    
    //save new state
    List<PersonData> newList = app.getPersonHelper().getPersons();
    
    //compare states
    oldList.add(person);
    Collections.sort(oldList);
    assertEquals(newList, oldList);
  }

}